<template>
    <div>
		<el-tabs v-model="activeName" @tab-click="handleClick" type="border-card"  style="margin-bottom:20px">
			<el-tab-pane name="0" label="代码规范检查">
				<el-row :gutter="30" style="margin-bottom:20px">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.code_style_check, [false, fomatFloat(labelsData.style_count * 1.8, 2)], 'frequency', common.titles[5], common.type)"
							:to_sub="common.to_sub + ' (目标<=' + fomatFloat(labelsData.style_count * 1.8, 2) + ')'"
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type2"
							:title="common.titles[9]"
							:num="String(labelsData.style_total_errors)"
							:sub="common.subs[3]"
							:to_sub="common.to_sub"
							:cls="common.danger"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type2"
							:title="common.titles[38]"
							:num="String(labelsData.style_count)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">							
						<info_label
							:type="'次数'"
							:title="'每Patch平均检查次数'"
							:num="String(labelsData.style_check_count)"
							:to_sub="common.to_sub "
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label>							
					</el-col>
					<!-- <el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(errorDensity, [false, 20], 'frequency', common.titles[39], common.avg)"
							:to_sub="common.to_sub + ' (目标<=20' + ')'"
							:sub="common.subs[3]"
							:cls="common.success"
						></info_label_compare>
					</el-col> -->
				</el-row>
				<el-row :gutter="30">
					
					<el-col :xs="24" :sm="24" :lg="6">
						<tag 
							title="checkpatch检查" 															
							unit="percent"
							:number="labelsData.checkpatch_pass_rate"
							numberName="通过率"
							:double="{value: labelsData.checkpatch_pass_count, numberName: '通过次数', unit: '次'}"
							></tag>				
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<tag 
							title="clint检查" 														
							unit="percent"
							:number="labelsData.clint_pass_rate"
							numberName="通过率"
							:double="{value: labelsData.clint_pass_count, numberName: '通过次数', unit: '次'}"
							></tag>							
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<tag 
							title="cpplint检查" 																
							unit="percent"
							:number="labelsData.cpplint_pass_rate"
							numberName="通过率"
							:double="{value: labelsData.cpplint_pass_count, numberName: '通过次数', unit: '次'}"
							></tag>							
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<tag 
							title="checkstyle检查" 																
							unit="percent"
							:number="labelsData.checkstyle_pass_rate"
							numberName="通过率"
							:double="{value: labelsData.checkstyle_pass_count, numberName: '通过次数', unit: '次'}"
							></tag>
					</el-col>
				</el-row>
				<!-- <el-row :gutter="30">
					
				</el-row> -->
				<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
					<div slot="header" class="clearfix">
						<span>代码规范检查</span>
					</div>
					<div>
						<ve-line
							:data="styleChartData"
							:settings="styleChartSettings"
							ref="line0"
							:data-empty="styleDataEmpty"
							:data-zoom="dataZoom"
						></ve-line>
					</div>
				</el-card>
				<el-card class="box-card m-b marT" shadow="never">
					<div slot="header" class="clearfix" style="vertical-align:middle">
						<div style="float: left; padding: 10px 0">平均检查通过趋势</div>
						<el-radio-group v-model="passTrend" style="float: right; padding: 3px 0" size="mini">
							<el-radio-button label="checkstyle指标"></el-radio-button>
							<el-radio-button label="cpplint指标"></el-radio-button>
							<el-radio-button label="clint指标"></el-radio-button>
							<el-radio-button label="checkpatch指标"></el-radio-button>
						</el-radio-group>
					</div>
					<div v-if="passTrend === 'checkstyle指标'">
						<ve-line
							ref="tline0"
							:data="checkstyle_data"
							:settings="codeChartSettings"
							:data-zoom="dataZoom"></ve-line>
					</div>
					<div v-else-if="passTrend === 'cpplint指标'">
						<ve-line
							ref="tline1"
							:data="cpplintstyle_data"
							:settings="codeChartSettings"
							:data-zoom="dataZoom"></ve-line>
					</div>
					<div v-else-if="passTrend === 'clint指标'">
						<ve-line
							ref="tline2"
							:data="clintstyle_data"
							:settings="codeChartSettings"
							:data-zoom="dataZoom"></ve-line>
					</div>
					<div v-else>
						<ve-line
							ref="tline3"
							:data="checkpatchstyle_data"
							:settings="codeChartSettings"
							:data-zoom="dataZoom"></ve-line>
					</div>
				</el-card>
				
			</el-tab-pane>
			<el-tab-pane name="1" label="代码静态检查">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.code_static_check, [false, fomatFloat(labelsData.static_count * 1.8, 2)], 'frequency', common.titles[4], common.type)"
							:to_sub="common.to_sub + ' (目标<=' + fomatFloat(labelsData.static_count * 1.8, 2) + ')'"
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type2"
							:title="common.titles[13]"
							:num="String(labelsData.static_total_errors)"
							:sub="common.subs[3]"
							:to_sub="common.to_sub"
							:cls="common.danger"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type2"
							:title="common.titles[38]"
							:num="String(labelsData.static_count)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="'次数'"
							:title="'每Patch平均检查次数'"
							:num="String(labelsData.static_check_count)"
							:to_sub="common.to_sub "
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label>							
					</el-col>
					
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							type="高"
							title="Coverity错误数"
							:num="String(labelsData.coverity_high)"
							:sub="common.subs[3]"
							:to_sub="common.type2"
							:cls="common.danger"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							type="中"
							title="Coverity错误数"
							:num="String(labelsData.coverity_medium)"
							:sub="common.subs[3]"
							:to_sub="common.type2"
							:cls="common.danger"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							type="低"
							title="Coverity错误数"
							:num="String(labelsData.coverity_low)"
							:sub="common.subs[3]"
							:to_sub="common.type2"
							:cls="common.danger"
						></info_label>
					</el-col>
					
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(coverity_high_err_density, [false, 20], 'frequency', common.titles[41], common.titles[42])"
							:to_sub="common.avg + ' (目标<=20)'"
							:sub="common.subs[3]"
							:cls="common.danger"
						></info_label_compare>
					</el-col>
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(coverity_medium_err_density, [false, 20], 'frequency', common.titles[41], common.titles[43])"
							:to_sub="common.avg + ' (目标<=20)'"
							:sub="common.subs[3]"
							:cls="common.danger"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(coverity_low_err_density, [false, 20], 'frequency', common.titles[41], common.titles[44])"
							:to_sub="common.avg + ' (目标<=20)'"
							:sub="common.subs[3]"
							:cls="common.danger"
						></info_label_compare>
					</el-col>
					
					<el-col :xs="24" :sm="24" :lg="6">
						<tag 
							title="coverity检查" 								 								
							unit="percent"
							:number="labelsData.coverity_pass_rate"
							numberName="通过率"
							:double="{value: labelsData.coverity_pass_count, numberName: '通过次数', unit: '次'}"
							></tag>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<tag 
							title="findbugs检查" 													
							unit="percent"
							:number="labelsData.findbugs_pass_rate"
							numberName="通过率"
							:double="{value: labelsData.findbugs_pass_count, numberName: '通过次数', unit: '次'}"
							></tag>
					</el-col>															
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="pclint检查" 								 								
								unit="percent"
								:number="labelsData.pclint_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.pclint_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>							
						</el-col>
				</el-row>
				<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
					<div slot="header" class="clearfix">
						<span>代码静态检查</span>
					</div>
					<div>
						<ve-line
							:data="staticChartData"
							:settings="staticChartSettings"
							ref="line1"
							:data-zoom="dataZoom"
							:data-empty="staticDataEmpty"
						></ve-line>
					</div>
				</el-card>
				<el-card class="box-card m-b marT" shadow="never">
					<div slot="header" class="clearfix">
						<span>平均检查通过趋势</span>
					</div>
					<div>
						<ve-line
							ref="zline1"
							:data="quality_trend_data"
							:settings="codeChartSettings"
							:data-zoom="dataZoom"></ve-line>
					</div>
				</el-card>
			</el-tab-pane>
			<el-tab-pane name="2" label="代码质量检查">
				<el-row :gutter="30" style="margin-bottom:20px">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type"
							:title="common.titles[6]"
							:num="String(labelsData.code_quality_check)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'平均'"
								:title="common.titles[11]"
								:num="String(labelsData.avg_simain_dupliate)"
								:sub="'行'"
								:to_sub="common.avg"
								:cls="common.danger"
							></info_label>
						</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(duplicateRate, [false, 5], 'percent', common.titles[40], common.avg)"
							:to_sub="common.type3 + ' (目标<=5%)'"
							:sub="common.subs[7]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type2"
							:title="common.titles[38]"
							:num="String(labelsData.quality_count)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
							<!-- <info_label_compare
								:params="generate_label_params(labelsData.avg_complexity, [true, kpi.avg_complexity], 'frequency', common.titles[10], common.avg)"
								:to_sub="common.avg + ' (目标<'+kpi.avg_complexity+')'"
								:cls="common.success">
							</info_label_compare> -->
							<LabelGrid
							:label_info="deptlableinfo.quan"
							:label_data="getFix(labelsData.avg_complexity)"
							:label_import="'small'"
							:label_precent="'num'"
							:nessary="true">
							</LabelGrid>
						</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.exceed_complexity_num, [false, 20], 'frequency', common.titles[31], common.type2)"
							:to_sub="common.to_sub + ' (目标<=18)'"
							:sub="common.subs[3]"
							:cls="common.danger"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.exceed_complexity_rate, [true, 80], 'percent', common.titles[32], common.avg)"
							:to_sub="common.type3 + ' (目标>=80%)'"
							:sub="common.subs[7]"
							:cls="common.danger"
						></info_label_compare>
					</el-col>
				</el-row>
				<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
					<div slot="header" class="clearfix">
						<span>代码质量检查</span>
					</div>
					<div>
						<ve-line
							:data="qualityChartData"
							:settings="qualityChartSettings"
							ref="line20"
							:data-zoom="dataZoom"
							:data-empty="qualityDataEmpty"
						></ve-line>
					</div>
				</el-card>
				<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
					<div slot="header" class="clearfix">
						<span>代码质量检查</span>
					</div>
					<div>
						<ve-line
							:data="qualityChartData1"
							:settings="qualityChartSettings1"
							ref="line21"
							:data-zoom="dataZoom"
							:data-empty="qualityDataEmpty1"
						></ve-line>
					</div>
				</el-card>
			</el-tab-pane>
			<el-tab-pane name="3" label="git log检查">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type"
							:title="common.titles[23]"
							:num="String(labelsData.git_log_check)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success">
						</info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="'次数'"
							:title="'每Patch平均检查次数'"
							:num="String(labelsData.git_check_count)"
							:to_sub="common.to_sub "
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label>							
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.git_log_rate, [true, 98], 'percent', common.titles[24], common.avg)"
							:to_sub="common.type3 + ' (目标>=98%)'"
							:sub="common.subs[7]"
							:cls="common.success">
						</info_label_compare>
					</el-col>
				</el-row>
			</el-tab-pane>
		</el-tabs>
		<el-card class="box-card m-b" shadow="never">
			<div slot="header" class="clearfix">
				<span>日统计汇总</span>
			</div>
			<div>
				<el-table
					:data="currentData"
					border
					style="width: 100%; margin-bottom: 20px"
					@sort-change="sortChange">
					<el-table-column prop="update_date" label="日期" width="100px" :sortable="'custom'"></el-table-column>
					<el-table-column prop="build" label="构建" width="100px" sortable></el-table-column>
					<el-table-column prop="code_style_check" label="代码规范检查" sortable></el-table-column>
					<el-table-column prop="code_static_check" label="代码静态检查" sortable></el-table-column>
					<el-table-column prop="code_quality_check" label="代码质量检查" sortable></el-table-column>
					<el-table-column prop="git_log_rate" label="Git log检查通过率" sortable></el-table-column>
					<el-table-column label="详情" width="120px">
							<template slot-scope="scope">
								<el-button
									type="primary"
									plain
									@click="viewDetail(scope.$index, scope.row)"
									size="medium"
								>查看详情</el-button>
							</template>
					</el-table-column>
				</el-table>
				<el-pagination
					@size-change="handleSizeChange"
					@current-change="handleCurrentChange"
					:current-page="currentPage"
					:page-sizes="[10, 15, 50, 100]"
					:page-size="currentSize"
					layout="total, sizes, prev, pager, next, jumper"
					:total="dataCount">
				</el-pagination>
			</div>
		</el-card>
    </div>
</template>

<script>
import { pagingData } from './utils.js';
import info_label from '@/components/devops/info_label.vue';
import info_label_compare from '@/components/devops/info_label_compare.vue';
import LabelGrid from '@/components/qa/Label.vue';
import { getHeader } from '@/app.config';
import common from '@/components/devops/get_data';
import 'v-charts/lib/style.css';
import 'echarts/lib/component/dataZoom';
import tag from '@/components/tags/index'
import http from '@/views/sys/axios'
export default {
    components: {
		info_label,
		info_label_compare,
		LabelGrid,
		tag
    },
    data () {
        this.dataZoom = [{
			type: 'slider',
			start: 0,
			end: 100
		}];
        return {
			common,
			deptlableinfo: {
				rate: {
					label_header: 'Avg',
					label_hname: 'git log检查通过率',
					label_unit: '(%)',
					label_class: 'success'
				},
				quan: {
					label_header: 'Avg',
					label_hname: '圈复杂度',
					label_unit: '',
					label_class: 'success'
				}
			},
			currentData: [],
			tableData: [],
			currentPage: 1,
			currentSize: 10,
			dataCount: 0,
			passTrend: 'checkstyle指标',
			coverity_high_err: 0,
			coverity_medium_err: 0,
			coverity_low_err: 0,
			coverity_high_err_density: 0,
			coverity_medium_err_density: 0,
			coverity_low_err_density: 0,
			status: 'down',
			// errorDensity: 0,
			duplicateRate: 0,
			codePlane: 7436694.8,
			codeMario: 8740531.6,
			codeLion: 1571878.2,
			styleChartData: {
				columns: [
					'update_date',
					'clint_errors',
					'cpplint_errors',
					'checkstyle_errors',
					'checkpatch_errors'
				],
				rows: []
			},
			styleChartSettings: {
				labelMap: {
					clint_errors: 'Clint错误数',
					cpplint_errors: 'Cpplint错误数',
					checkstyle_errors: 'Checkstyle错误数',
					checkpatch_errors: 'Checkpatch错误数'
				}
			},
			staticChartData: {
				columns: [
					'update_date',
					'findbugs_high',
					'findbugs_medium',
					'findbugs_low',
					'coverity_high',
					'coverity_medium',
					'coverity_low',
					'pclint_errors'
				],
				rows: []
			},
			staticChartSettings: {
				labelMap: {
					findbugs_high: 'Findbugs错误数(高)',
					findbugs_medium: 'Findbugs错误数(中)',
					findbugs_low: 'Findbugs错误数(低)',
					coverity_high: 'Coverity错误数(高)',
					coverity_medium: 'Coverity错误数(中)',
					coverity_low: 'Coverity错误数(低)',
					pclint_errors: 'Pclint错误数'
				}
			},
			qualityChartData: {
				columns: [
					'update_date',
					'av_c_block_depth',
					'av_cpp_block_depth',
					'av_java_block_depth'
				],
				rows: []
			},
			quality_trend_data: {
				columns: ['update_date', 'findbugs_pass_count', 'coverity_pass_count', 'pclint_pass_count', 'findbugs_pass_rate', 'coverity_pass_rate', 'pclint_pass_rate'],
				rows: []
			},
			checkstyle_data: {
				columns: ['update_date', 'checkstyle_pass_count', 'checkstyle_pass_rate'],
				rows: []
			},
			cpplintstyle_data: {
				columns: ['update_date', 'cpplint_count', 'cpplint_pass_count'],
				rows: []
			},
			clintstyle_data: {
				columns: ['update_date', 'clint_count', 'clint_pass_count'],
				rows: []
			},
			checkpatchstyle_data: {
				columns: ['update_date', 'checkpatch_pass_count', 'checkpatch_pass_rate'],
				rows: []
			},
			qualityChartSettings: {
				labelMap: {
					av_c_block_depth: '平均块深度(C)',
					av_cpp_block_depth: '平均块深度(CPP)',
					av_java_block_depth: '平均块深度(JAVA)'
				}
			},
			qualityChartData1: {
				columns: ['update_date', 'simian_duplicate'],
				rows: []
			},
			qualityChartSettings1: {
				labelMap: {
					simian_duplicate: '代码重复行数'
				}
			},
			styleDataEmpty: true,
			staticDataEmpty: true,
			qualityDataEmpty: true,
			qualityDataEmpty1: true,
			labelsData: {},
			codeChartSettings: {
				labelMap: {
					avg_static_errors: '代码静态检查错误数',
					avg_style_errors: '代码规范检查错误数',
					git_pass_rate: 'git log通过率(%)',
					avg_duplicate: '代码重复行数',
					avg_complexity: '圈复杂度',
					checkstyle_pass_count: 'checkstyle检查通过次数(次)',
					cpplint_pass_count: 'cpplint检查通过次数(次)',
					checkstyle_pass_rate: 'checkstyle检查通过率(%)',
					cpplint_pass_rate: 'cpplint检查通过率(%)',
					clint_pass_rate: 'clint检查通过率(%)',
					clint_pass_count: 'clint检查通过次数',
					coverity_pass_count: 'coverity检查通过次数(次)',
					findbugs_pass_count: 'findbugs检查通过次数(次)',
					pclint_pass_count: 'pclint检查通过次数(次)',
					coverity_pass_rate: 'coverity检查通过率(%)',
					findbugs_pass_rate: 'findbugs检查通过率(%)',
					pclint_pass_rate: 'pclint检查通过率(%)',
					checkpatch_pass_count: 'checkpatch检查通过次数',
					checkpatch_pass_rate: 'checkpatch检查通过率(%)'
				}
			},
			activeName: '0',
        }
    },
    props: {
        params: Object
    },
    methods: {
		handleClick(tab, event) {},
		init_datas(projectId, date) {
			this.getTrend(projectId, date);
			this.get_data_by_url(projectId, date);
			this.get_table_data(projectId, date);
		},
		filterObject: function() {
			console.log('111')
		},
		getFix(data) {
				if (null == data || "undefined" == typeof(data) || "" == data) {
						return 0;
				} else {
						return data
				}
		},
		sortChange: function(val) {
			var key = val['prop'];
			var compare1 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return -1;
				} else if (val1 > val2) {
					return 1;
				} else {
					return 0;
				}
			};
			var compare2 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return 1;
				} else if (val1 > val2) {
					return -1;
				} else {
					return 0;
				}
			};
			var arr = this.tableData;
			if (val['order'] === 'ascending') {
				this.currentData = pagingData(arr.sort(compare1), this.dataCount, this.currentPage, this.currentSize);
			} else if (val['order'] === 'descending') {
				this.currentData = pagingData(arr.sort(compare2), this.dataCount, this.currentPage, this.currentSize);
			} else {
				key = 'update_date';
				this.currentData = pagingData(arr.sort(compare2), this.dataCount, this.currentPage, this.currentSize);
			}
		},
		handleSizeChange: function(size) {
			this.currentSize = size;
			this.currentData = pagingData(this.tableData, this.dataCount, this.currentPage, this.currentSize);
		},
		handleCurrentChange: function(page) {
			this.currentPage = page;
			this.currentData = pagingData(this.tableData, this.dataCount, this.currentPage, this.currentSize);
		},
		viewDetail(index, row) {
			let routeData = this.$router.resolve({
				path:
					'/project/details/' +
					this.params.projectId + '/' +
					this.params.projectName +
					'_@_' +
					row.update_date +
					'_@_codecheck'
			});
			window.open(routeData.href, '_blank');
		},
		getTrend(projectId, date) {
			http.get(`${process.env.VUE_APP_KANBAN_HOST}/api/devops/dept/check/pass/trend?projectId=${projectId}&date=${date}`)
			.then(res => {
				if(res.code == 200) {
					this.quality_trend_data.rows = res.quality_trend_data
					
					let data = res.style_trend_data								
					this.checkstyle_data.rows = data
					this.cpplintstyle_data.rows = data
					this.clintstyle_data.rows = data
					this.checkpatchstyle_data.rows = data
					this.checkstyle_data.rows.forEach(val => {
						val.checkstyle_pass_rate = val.checkstyle_pass_rate*100
					})
					this.cpplintstyle_data.rows.forEach(val => {
						val.cpplint_pass_rate = val.cpplint_pass_rate*100
					})
					this.clintstyle_data.rows.forEach(val => {
						val.clint_pass_rate = val.clint_pass_rate*100
					})
					
					this.checkpatchstyle_data.rows.forEach(val => {
						val.checkpatch_pass_rate = val.checkpatch_pass_rate*100
					})

					this.quality_trend_data.rows.forEach(val => {
						val.coverity_pass_rate = val.coverity_pass_rate*100
						val.findbugs_pass_rate = val.findbugs_pass_rate*100
						val.pclint_pass_rate = val.pclint_pass_rate*100
					})
				}
			})
		},
		fomatFloat(src, pos) {
			return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
		},
		generate_label_params: function(val1, val2, dataType, dataTitle, label) {
			if (typeof val1 === 'undefined') {
				val1 = 0;
			}
			var labelParam;
			if (dataType === 'time') {
				var standardTime = val2[1] * 60;
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'reach' : 'down',
							difference:
								val1 > standardTime
									? ''
									: this.formatSeconds(standardTime - val1)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'up' : 'reach',
							difference:
								val1 > standardTime
									? this.formatSeconds(val1 - standardTime)
									: ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.formatSeconds(val1),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'percent') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2) + '%',
							num: this.fomatFloat(val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) + '%' : '',
							num: this.fomatFloat(val1, 2)
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						status: 'reach',
						difference: '',
						num: this.fomatFloat(val1, 2)
					};
				}
				return labelParam;
			} else if (dataType === 'frequency') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'multiple') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else {
				labelParam = {
					type: label,
					title: dataTitle,
					num: this.fomatFloat(val1, 2),
					status: 'reach',
					difference: ''
				};
				return labelParam;
			}
		},
		formatSeconds(value) {
			if (isNaN(value)) {
				value = 0;
			}
			var theTime = parseInt(value); // 秒
			var theTime1 = 0; // 分
			var theTime2 = 0; // 小时
			var theTime3 = 0; // 天
			if (theTime > 60) {
				theTime1 = parseInt(theTime / 60);
				theTime = parseInt(theTime % 60);
				if (theTime1 > 60) {
					theTime2 = parseInt(theTime1 / 60);
					theTime1 = parseInt(theTime1 % 60);
					if (theTime2 > 24) {
						theTime3 = parseInt(theTime2 / 24);
						theTime2 = parseInt(theTime2 % 24);
					}
				}
			}
			var result = '' + parseInt(theTime) + '秒';
			if (theTime1 > 0) {
				result = '' + parseInt(theTime1) + '分' + result;
			}
			if (theTime2 > 0) {
				result = '' + parseInt(theTime2) + '时' + result;
			}
			if (theTime3 > 0) {
				result = '' + parseInt(theTime3) + '天' + result;
			}
			return result;
		},
		get_table_data: function(projectId, date) {
			this.currentData = [];
			this.tableData = [];
			this.styleDataEmpty = true;
			this.staticDataEmpty = true;
			this.qualityDataEmpty = true;
			this.qualityDataEmpty1 = true;
			var self = this;
			this.$axios
				.get(
					process.env.VUE_APP_KANBAN_HOST +
						'/api/devops/project/table/summary?projectId=' +
						projectId +
						'&date=' +
						date +
						'&page=codecheck',
					{headers: getHeader()}
				)
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data.table;
							for (var i = 0; i < data.length; i++) {
								var tableDict = {
									update_date: data[i]['update_date'],
									build: data[i]['build'] + '次',
									code_style_check: data[i]['code_style_check'] + '次',
									code_static_check: data[i]['code_static_check'] + '次',
									code_quality_check: data[i]['code_quality_check'] + '次',
									git_log_rate: data[i]['git_log_rate'] + '%'
								};
								self.tableData.push(tableDict);
							}
							self.dataCount = self.tableData.length;
							self.currentPage = 1;
							self.currentSize = 10;
							if (self.dataCount === 0) {
								self.currentData = [];
							} else {
								self.currentData = pagingData(self.tableData, self.dataCount, self.currentPage, self.currentSize);
							}
							self.styleChartData.rows = response.data.chart.code_style_check;
							if (self.styleChartData.rows.length > 0) {
								self.styleDataEmpty = false;
							}
							self.staticChartData.rows = response.data.chart.code_static_check;
							if (self.staticChartData.rows.length > 0) {
								self.staticDataEmpty = false;
							}
							self.qualityChartData.rows =
								response.data.chart.code_quality_check;
							if (self.qualityChartData.rows.length > 0) {
								self.qualityDataEmpty = false;
							}
							self.qualityChartData1.rows =
								response.data.chart.code_quality_check;
							if (self.qualityChartData1.rows.length > 0) {
								self.qualityDataEmpty1 = false;
							}
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
		get_data_by_url: function(projectId, date) {
			this.labelsData = {};
			// this.errorDensity = 0;
			this.duplicateRate = 0;
			this.coverity_high_err_density = 0;
			this.coverity_medium_err_density = 0;
			this.coverity_low_err_density = 0;
			var self = this;
			this.$axios
				.get(
					process.env.VUE_APP_KANBAN_HOST +
						'/api/devops/project/summary?projectId=' +
						projectId +
						'&date=' +
						date +
						'&page=codecheck',
					{headers: getHeader()}	
				)
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data;
							self.labelsData = data.data;
							// if (self.project === 'Plane V2.0') {
							// 	self.errorDensity = (
							// 		(self.labelsData.style_total_errors / self.codePlane) *
							// 		1000
							// 	).toFixed(2);
							// 	self.duplicateRate = (
							// 		(self.labelsData.simian_duplicate / self.codePlane) *
							// 		100
							// 	).toFixed(2);
							// } else if (self.project === 'Mario-Project-2018v01') {
							// 	self.errorDensity = (
							// 		(self.labelsData.style_total_errors / self.codeMario) *
							// 		1000
							// 	).toFixed(2);
							// 	self.duplicateRate = (
							// 		(self.labelsData.simian_duplicate / self.codeMario) *
							// 		100
							// 	).toFixed(2);
							// } else if (self.project === 'Lion-A5') {
							// 	self.errorDensity = (
							// 		(self.labelsData.style_total_errors / self.codeLion) *
							// 		1000
							// 	).toFixed(2);
							// 	self.duplicateRate = (
							// 		(self.labelsData.simian_duplicate / self.codeLion) *
							// 		100
							// 	).toFixed(2);
							// }
							self.coverity_high_err_density = self.labelsData.static_count
								? self.labelsData.coverity_high / self.labelsData.static_count
								: 0;
							self.coverity_medium_err_density = self.labelsData.static_count
								? self.labelsData.coverity_medium / self.labelsData.static_count
								: 0;
							self.coverity_low_err_density = self.labelsData.static_count
								? self.labelsData.coverity_low / self.labelsData.static_count
								: 0;
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
    },
    watch: {
        params: {
			handler: function(val) {
				console.log('watchpro')
				let projectId = val.projectId === 'undefined' ? '' : val.projectId;
				let dates = val.time === 'undefined' ? '' : val.time;
				this.init_datas(projectId, dates);
			},
			deep: true
        },
        activeName(v) {
					this.passTrend = 'checkstyle指标'
					if (v === '2') {
						this.$nextTick(_ => {
							this.$refs['line20'].echarts.resize();
							this.$refs['line21'].echarts.resize();
						});
					} else if(v === '1') {
						this.$nextTick(() => {
							this.$refs['zline1'].echarts.resize();
						});
					} else {
						this.$nextTick(_ => {
							this.$refs[`line${v}`].echarts.resize();
						});
					}
			},
			passTrend(val) {
				this.$nextTick(() => {
					if(val == 'checkstyle指标') {
						this.$refs[`tline0`].echarts.resize()
					} else if(val == 'cpplint指标') {
						this.$refs[`tline1`].echarts.resize()
					} else if(val == 'clint指标') {
						this.$refs[`tline2`].echarts.resize()
					} else {
						this.$refs[`tline3`].echarts.resize()
					}
				})			
			}
    },
    // mounted() {
	// 		let projectId = this.params.projectId === 'undefined' ? '' : this.params.projectId;
	// 		let dates = this.params.time === 'undefined' ? '' : this.params.time;
	// 		this.init_datas(projectId, dates);
	// }
}
</script>
